﻿using Cysharp.Threading.Tasks;
using UnityEngine;

public class HintPanel : UIPanelBase
{
    [SerializeField]
    private GameObject m_Prefab;
    [SerializeField]
    private Transform m_ContentRoot;

    private ObjectPool<HintItem> m_Pool;

    public override void OnInit()
    {
        m_Pool = new ObjectPool<HintItem>(m_Prefab);
    }

    private async void SpawnHintItem(string hintText, float duration)
    {
        var hintItem = m_Pool.Rent();
        hintItem.transform.SetParent(m_ContentRoot);
        hintItem.transform.localPosition = Vector3.zero;
        hintItem.SetItem(hintText, duration);
        await UniTask.WaitForSeconds(duration);
        m_Pool.Return(hintItem);
    }

    public static void ShowHint(string hintText, float duration = 2f)
    {
        UIManager.Show<HintPanel>().SpawnHintItem(hintText, duration);
    }
}